<!DOCTYPE html>
<html>
<head>
    <title>Phase Separation of Helium Isotopes</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        canvas {
            border: 1px solid #ccc;
            background-color: #fff;
        }
    </style>
</head>
<body>
    <canvas id="heliumPhasesCanvas" width="650" height="350"></canvas>
    <script>
        const canvas = document.getElementById('heliumPhasesCanvas');
        const ctx = canvas.getContext('2d');

        // Use a font that mimics handwriting
        const mainFont = '20px "Comic Sans MS", cursive, sans-serif';
        const supFont = '14px "Comic Sans MS", cursive, sans-serif';
        const captionFont = '18px "Comic Sans MS", cursive, sans-serif';

        // --- Drawing parameters ---
        const containerX = 50;
        const containerY = 80;
        const containerWidth = 300;
        const containerHeight = 120;

        ctx.strokeStyle = 'black';
        ctx.fillStyle = 'black';
        ctx.lineWidth = 2;

        // 1. Draw the container
        ctx.strokeRect(containerX, containerY, containerWidth, containerHeight);

        // 2. Draw the phase interface
        const interfaceY = containerY + containerHeight * 0.4;
        ctx.beginPath();
        ctx.moveTo(containerX, interfaceY);
        ctx.lineTo(containerX + containerWidth, interfaceY);
        ctx.stroke();

        // 3. Draw the stippling in the dilute phase (bottom layer)
        const dotCount = 180;
        const dotRadius = 1.2;
        for (let i = 0; i < dotCount; i++) {
            // Generate random x and y within the bottom part of the container
            const x = containerX + 5 + Math.random() * (containerWidth - 10);
            const y = interfaceY + 5 + Math.random() * (containerHeight * 0.6 - 10);
            
            ctx.beginPath();
            ctx.arc(x, y, dotRadius, 0, 2 * Math.PI);
            ctx.fill();
        }

        // 4. Draw labels and leader lines
        const leaderStartX = containerX + containerWidth;
        const leaderEndX = leaderStartX + 20;
        const textStartX = leaderEndX + 10;
        
        ctx.textAlign = 'left';
        ctx.textBaseline = 'middle';

        // Label for the concentrated phase (top)
        const topLeaderY = containerY + (interfaceY - containerY) / 2;
        ctx.beginPath();
        ctx.moveTo(leaderStartX, topLeaderY);
        ctx.lineTo(leaderEndX, topLeaderY);
        ctx.stroke();
        
        let currentX = textStartX;
        ctx.font = mainFont;
        ctx.fillText('concentrated phase of ', currentX, topLeaderY);
        currentX += ctx.measureText('concentrated phase of ').width;
        
        ctx.font = supFont;
        ctx.fillText('3', currentX, topLeaderY - 8); // Superscript
        currentX += ctx.measureText('3').width;
        
        ctx.font = mainFont;
        ctx.fillText('He', currentX, topLeaderY);

        // Label for the dilute phase (bottom)
        const bottomLeaderY = interfaceY + (containerHeight + containerY - interfaceY) / 2;
        ctx.beginPath();
        ctx.moveTo(leaderStartX, bottomLeaderY);
        ctx.lineTo(leaderEndX, bottomLeaderY);
        ctx.stroke();
        
        // First line of bottom label
        const bottomTextY1 = bottomLeaderY - 12;
        currentX = textStartX;
        ctx.font = mainFont;
        ctx.fillText('dilute phase of ', currentX, bottomTextY1);
        currentX += ctx.measureText('dilute phase of ').width;

        ctx.font = supFont;
        ctx.fillText('3', currentX, bottomTextY1 - 8); // Superscript
        currentX += ctx.measureText('3').width;

        ctx.font = mainFont;
        ctx.fillText('He', currentX, bottomTextY1);

        // Second line of bottom label
        const bottomTextY2 = bottomLeaderY + 12;
        currentX = textStartX;
        ctx.font = mainFont;
        ctx.fillText('(in superfluid of ', currentX, bottomTextY2);
        currentX += ctx.measureText('(in superfluid of ').width;
        
        ctx.font = supFont;
        ctx.fillText('4', currentX, bottomTextY2 - 8); // Superscript
        currentX += ctx.measureText('4').width;

        ctx.font = mainFont;
        ctx.fillText('He)', currentX, bottomTextY2);

        // 5. Draw the figure caption
        ctx.font = captionFont;
        ctx.textAlign = 'center';
        ctx.fillText('Fig. 2.23.', containerX + containerWidth / 2, containerY + containerHeight + 40);

    </script>
</body>
</html>